package o2o.web.actions.notice;


// 电话通知

import com.jinyou.utils.common.DateUtils;
import com.jinyou.utils.common.ValidateUtil;
import com.jinyouapp.client.tel.TelCallClient;
import com.jinyouapp.client.tel.exception.TelCallException;
import com.jinyouapp.client.tel.model.TtsCallResponseInfo;
import o2o.cache.sys.SysCustomerCache;
import o2o.dao.PO.sys.SysCustomerInfo;

import java.util.List;

public class PhoneNotice {

    public static boolean callPhone(String sysAppKey, String phone, String type, String content) {
        if (ValidateUtil.isNull(phone) || ValidateUtil.isNull(type)) {
            return false;
        }
        if (ValidateUtil.isNull(sysAppKey)) {
            sysAppKey = SysCustomerCache.getInstance().getDefaultKey();
        }

        SysCustomerInfo customerInfo = SysCustomerCache.getInstance().getInfo(sysAppKey);
        if (null == customerInfo) {
            return false;
        }


//        TelCallClient telCallClient = TelCallClient.getInstance().setSysCustomer(customerInfo.getPhoneKey()).setPhone(phone).setType(type);
//
////        if (ValidateUtil.isNotNull(content)) {
////            telCallClient.setParam("event", content);
////        }
////        telCallClient.setParam("location", customerInfo.getName()).setParam("equipment", "有新订单");
//
//        // 外卖用的参数 tts-zhenweikang   tts-chisha
//        telCallClient.setParam("app", customerInfo.getName());
//
//        List<TtsCallResponseInfo> list = null;
//        try {
//            list = telCallClient.telCall();
//            System.out.println(DateUtils.getCurrentDateTime() + "  " + customerInfo.getPhoneKey() + "   " + sysAppKey + "通知商家：" + phone);
//        } catch (TelCallException e) {
//            e.printStackTrace();
//            return false;
//        }

        List<TtsCallResponseInfo> list = null;
        try {
            list =  TelCallClient.getInstance().setSysCustomer(customerInfo.getPhoneKey())
                    .setPhone(phone).setType(type).setParam("app", customerInfo.getName()).telCall();
            System.out.println(DateUtils.getCurrentDateTime() + "  " + customerInfo.getPhoneKey() + "   " + customerInfo.getName() + "通知商家：" + phone);
        } catch (TelCallException e) {
            e.printStackTrace();
        }


        if (null == list) {
            return false;
        }
        return true;


//        try {
//            List<TtsCallResponseInfo> list = TelCallClient.getInstance().setSysCustomer("iot-beiren").setPhone("15666371607").setType("tts_alarm_notice").setParam("location", "公司").setParam("equipment", "订单11122220001").setParam("event", "请尽快接单").telCall();
//            System.out.println(JSON.toJSON(list));
//        } catch (TelCallException var2) {
//            var2.printStackTrace();
//        }
    }

}
